package jddk;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public class Test1 {

	public void getType(String type) {
		if (type.equals("2")) {
			type = "4";
		}
		System.out.println("type: " + type);
	}

	public static void main(String[] args) {

		/*List<EnableAutoConfiguration> aa = SpringFactoriesLoader.loadFactories(EnableAutoConfiguration.class, Test1.class.getClassLoader());
		
		for (EnableAutoConfiguration enableAutoConfiguration : aa) {
			System.out.println(enableAutoConfiguration);
		}*/

		Map<String, List<String>> mapList = new HashMap<String, List<String>>();
		mapList.computeIfAbsent("a", (key) -> {
			return new ArrayList<>();
		}).add("adddddd");

		//HashMap computeIfAbsent() - 如果指定键未映射到任何值，则计算该值
		//HashMap computeIfPresent() - 如果指定的键已经映射到一个值，则计算该值
		//mapList.compute(key, remappingFunction)//重新计算key对应的新的值,并覆盖

		System.out.println(mapList);
		mapList.replaceAll((factoryType, implementations) -> implementations.stream().distinct().collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)));

		System.out.println(mapList);

	}

	public static void bbaaa() {
		List<Map<String, String>> mzList = new ArrayList<Map<String, String>>();

		List<String> newlines = Lists.newArrayList();

		try {
			List<String> lines = FileUtils.readLines(new File("E:/minzu.txt"));

			for (String string : lines) {
				if (StringUtils.isBlank(string)) {
					continue;
				}

				String mz = StringUtils.trimToEmpty(string);

				if (StringUtils.isNumeric(mz) || StringUtils.contains(mz, "族")) {
					newlines.add(mz);
				}

			}

			for (int i = 0; i < newlines.size(); i += 2) {

				Map<String, String> map = null;

				if (i % 2 == 0) {
					map = Maps.newHashMap();
				}

				String code = newlines.get(i);
				String value = newlines.get(i + 1);
				map.put("id", code);
				map.put("text", value);
				mzList.add(map);
			}

			Collections.sort(mzList, new Comparator<Map<String, String>>() {

				@Override
				public int compare(Map<String, String> var1, Map<String, String> var2) {
					int id1 = Integer.parseInt(var1.get("id"));
					int id2 = Integer.parseInt(var2.get("id"));
					int index = id1 - id2;
					return index;
				}

			});

			System.out.println(JSON.toJSONString(mzList, true));

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
